/*
  Receives compass sensor events from your phone.
*/
 
#include <MeetAndroid.h>

// MeetAndroid meetAndroid();
// you can define your own error function to catch messages
// where not fuction has been attached for
MeetAndroid wilfred(pos);  //set wilfred and position serial output

void pos(uint8_t flag, uint8_t values){  //flag is default A ???on values
  Serial.print("ERROR: ");
  Serial.print(flag);
}

int yled = 13;
int xled = 2;

void setup(){
  Serial.begin(9600);
  pinMode(yled, OUTPUT);
  pinMode(xled, OUTPUT); 
  
  // register callback functions, which will be called when an associated event occurs.
  // - the first parameter is the name of your function (see below)
  // - match the second parameter ('A', 'B', 'a', etc...) with the flag on your Android application
  wilfred.registerFunction(acc, 'A');  
}

void loop()
{
  wilfred.receive(); //recieves all events being sent
}

/*
 * This method is called constantly.
 * note: flag is in this case 'A' and numOfValues is 1 
 * since compass event sends exactly one single int value for heading
 */
void acc(byte flag, byte numOfValues)
{
  int yaxis= wilfred.getInt(); //getint is 3 values between 0 and 26 ??? still working on specifics
  FW(yaxis); // silly, you should have better ideas
  //int xaxis= wilfred.getInt();
  /*LF(xaxis);
  int zaxis=wilfred.getInt();
  //tocome*/
}

void FW(int temp) //move forward
{
  //digitalWrite(yled, HIGH);
  //delay(100);
  //digitalWrite(yled, LOW);
  Serial.println("Moving Foraward");
  digitalWrite(yled, HIGH);
  Serial.println(temp);
}

/*void LF() //move sideways
{
  digitalWrite(yled, HIGH);
  delay(100);
  digitalWrite(yled, LOW);
}*/

